export function validatePhone(val) {
	var reg = /^0?1[3|4|5|7|8]\d{9}$/;
	return reg.test(val)
}

export function vaildateSmsCode(val) {
	var reg = /[a-zA-Z0-9]{6}/;
	return reg.test(val)
}

//邮箱
export function validateEmail(val) {
	var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	return reg.test(val)
}

// 获取唯一标识的字符串,用于图片验证码
export function getUuid() {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}


/**
 * 
 * @param {表格同比格式化} point 
 * @returns 
 */
export function toPercent(point) {
	// var percent = Number(point * 100).toFixed(1);
	if (point == undefined) {
		return '-';
	}

	if (point == 0) {
		return Number(point * 100).toFixed(2) + "%";
	}

	var percent = Number(point * 100).toFixed(2);
	percent += "%";
	if (percent.indexOf('-') == -1) {
		percent = '+' + percent;
	}
	return percent;
}


/**
 * 
 * @param {表格数值格式化} point 
 * @returns 
 */
export function numberToPercent(point) {
	if (point == undefined) {
		return '-';
	}
	return point;
}



/**
 * 
 * @param {不带加号} point 
 * @returns 
 */
export function toPercentNotAdd(point) {
	// var percent = Number(point * 100).toFixed(1);
	var percent = Number(point * 100).toFixed(2);
	percent += "%";
	return percent;
}


/**
 * 
 * @param {小时格式转换02-01} point 
 * @returns 
 */
export function toFormatH(start) {
	if (start == '累计') return start;
	let end = Number.parseInt(start) + 1;
	if (end == NaN) {
		return start;
	}
	//前面补0代码
	// if (end < 10) {
	// 	end = '0' + end;
	// }
	// if (start < 10) {
	// 	start = '0' + start;
	// }
	return Number.parseInt(start) + '-' + end;
}